package algo3.vista;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import fiuba.algo3.titiritero.dibujables.SuperficiePanel;

public class SuperficiePanelConFondo extends SuperficiePanel {

	private static final long serialVersionUID = 1L;
	protected Image imagen;
	protected Image imagenFondo;

	public void setImagen(Image imagen) {
		this.imagenFondo = imagen;
	}
	
	public void paint(Graphics g) {
		System.out.println("repintando");
		g.drawImage(this.imagen, 0, 0, null);
		g.setColor(Color.black);
		int tamanioCelda = SistemaCoordenadas.getTamanioCelda();
        for (int m=0;m<10;m++){
            for (int n=0;n<10;n++){
            	g.drawRect(m * tamanioCelda, n * tamanioCelda, tamanioCelda, tamanioCelda);
            }
        }
		this.limpiar();
	}
	
	private void limpiar() {
		if(this.imagen == null)
			this.imagen = this.createImage(getSize().width, getSize().height);
		Graphics superficieParaDibujar =  this.imagen.getGraphics();
		superficieParaDibujar.drawImage(this.imagenFondo, 0, 0, null);
	}
	
	public Graphics getBuffer(){
		return this.imagen.getGraphics();
	}
}